"""remove_columns_aaa

Revision ID: 7b5c0116f621
Revises: 0586897cb73c
Create Date: 2025-06-16 22:45:04.517646

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '7b5c0116f621'
down_revision: Union[str, None] = '0586897cb73c'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    # SQLite不支持ALTER COLUMN，跳过这个操作
    # op.alter_column('trades', 'notes',
    #            existing_type=sa.TEXT(),
    #            type_=sa.String(),
    #            existing_nullable=True)
    
    # 创建唯一约束
    try:
        op.create_unique_constraint(None, 'trades', ['trade_id'])
    except Exception:
        # 如果约束已存在则跳过
        pass
    
    # 删除列
    try:
        op.drop_column('trades', 'aaa')
    except Exception:
        # 如果列不存在则跳过
        pass
    
    try:
        op.drop_column('trades', 'test4')
    except Exception:
        # 如果列不存在则跳过
        pass
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('trades', sa.Column('test4', sa.VARCHAR(), nullable=True))
    op.add_column('trades', sa.Column('aaa', sa.VARCHAR(), nullable=True))
    try:
        op.drop_constraint(None, 'trades', type_='unique')
    except Exception:
        # 如果约束不存在则跳过
        pass
    # SQLite不支持ALTER COLUMN，跳过这个操作
    # op.alter_column('trades', 'notes',
    #            existing_type=sa.String(),
    #            type_=sa.TEXT(),
    #            existing_nullable=True)
    # ### end Alembic commands ###
